<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>

<div id="app">
    姓：<input type="text" v-model="firstName">+
    名：<input type="text" v-model="lastName">=
    <span>姓名：{{fullName}}</span><br><br>
    <button @click="changeName">修改姓名</button>
</div>
<script src="./vue.js"></script>
<script>
    const app = new Vue({
        el: '#app',
        data: {
            firstName: "刘",
            lastName: "备"
        },
        computed: {
            // 基础写法是简写：只能获取，不能设置
            // fullName() {
            //     return this.firstName + this.lastName
            // }

            // 完整写法，设置 get、set 方法
            fullName: {
                get() {
                    return this.firstName + this.lastName
                },
                set(value) {
                    console.log(value)
                    this.firstName = value.slice(0, 1)
                    this.lastName = value.slice(1)
                }
            }
        },
        methods: {
            changeName() {
                // 直接对计算属性进行赋值
                this.fullName = "吕da布"
            }
        }
    })
</script>
</body>
</html>